<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript">
	function check1(memo){
		var ari_max=200;
		var ls_str = memo.value; //이벤트가 일어난 컨트롤의 valuet
		var li_str_len = 0; //substring하기 위해서 사용
		var ls_one_char = ""; //한글자씩 검사한다
		var ls_str2 = ""; // 글자수를 초과하면 제한한 수 글자전까지만 보여줌
		
		for(i=0; i<li_str_len; i++){
			//한글자 추출
			ls_one_char = ls_str.charAt(i);
			
			//한글이면 2를 더한다
			if(escape(ls_one_char).length > 4){
				li_byte += 2;
			}else{ //그밖의 경우는 1을 더한다.
				li_byte++;
			}
			//전체 크기가 li_max를 넘지않으면
			if(li_byte<= li_max){
				li_len = i+1;
			}
			}
				//전체길이를 초과하면
		if(li_byte > li_max){
			alert("200글자를 초과 입력할 수 없습니다. \n 초과된 내용은 자동으로 삭제	 됩니다.");
			ls_str2 = ls_str.substr(0,li_len);
			memo.value= ls_str2;
		}
		memo.focus();
		}
</script>
<fieldset id="writeBoard">
<legend>글작성</legend>
<ul>
 	
	<spring:hasBindErrors name="command"/>
	<form:errors path="command"/>
	
	<form action="boardWrite.do" enctype="multipart/form-data" method="post">
	<li>
	<label><spring:message code="write.form.m_id"/></label>
	<input type="text" name="m_id" value="${userId}" style="background-color: #f3f3f3" readonly="readonly"><br>
	</li>
	<li>
	<label><spring:message code="write.form.b_title"/></label>
	<input type="text" name="b_title">
	<font style="font-weight: bold;color:red"><form:errors path="command.b_title"/></font><br>
	</li>
	<li>
	<label><spring:message code="write.form.b_content"/></label>
	<textarea name="b_content" rows="10" cols="50" maxlength="200" onkeyup="check1(this);" style="resize:none">${command.b_content}</textarea>
	<font style="font-weight: bold;color:red"><form:errors path="command.b_content"/></font><br>
	</li>
	<li>
	<label><spring:message code="write.form.upload"/></label>
	<input type="file" name="upload"><br>
	</li>
	<li>
	<label>	<spring:message code="write.form.b_open"/></label>
	<input type="radio" name="b_open" value="0" checked="checked">공개&nbsp;&nbsp;
	<input type="radio" name="b_open" value="1">비공개&nbsp;&nbsp;
	<c:if test="${userLevel > 3 }">
	<input type="radio" name="b_open" value="2">공지사항&nbsp;&nbsp;
	</c:if>
	<font style="font-weight: bold;color:red"><form:errors path="command.b_open"/></font><br>
	</li>
	<div align="center">	
	<input type="submit" value="<spring:message code="write.form.submit"/>" style="width: 120px;height: 22px">
	<input type="button" value="<spring:message code="list.content.title"/>" style="width: 120px;height: 22px"
		onclick="location.href='boardList.do'">
	</div>
</ul>
</form>
</fieldset>